package cn.qyd.io;


import java.io.*;

/**
 * @author 邱运铎
 * @date 2024-03-18 0:07
 */
public class AllDemo {
    public static void main(String[] args) {
        try {
            FileInputStream fileInputStream = new FileInputStream("src\\cn\\qyd\\io\\input.txt");
            FileOutputStream outputStream = new FileOutputStream("src\\cn\\qyd\\io\\output.txt");
            int len;
            byte[] bufferByte = new byte[1024];
            while ((len = fileInputStream.read(bufferByte)) != -1) {
                outputStream.write(bufferByte,0,len);
                System.out.println(new String(bufferByte,"UTF-8").substring(0,len));
            }
        } catch (IOException e) {
           e.printStackTrace();
        }

        try {
            FileReader fileReader = new FileReader("src\\cn\\qyd\\io\\input.txt");
            FileWriter fileWriter = new FileWriter("src\\cn\\qyd\\io\\writeOutput.txt");
            char[] bufferChar = new char[1024];
            int len1;
            fileWriter.write(new char[]{'1','2'});
            if ((len1 = fileReader.read(bufferChar)) != -1) {
                System.out.println("i am reader writer" + new String(bufferChar).substring(0,len1));
                System.out.println(bufferChar.length);
                fileWriter.write(bufferChar,0,len1);
            }
            fileWriter.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
